package com.wangju.chapter5;

import com.wangju.chapter5.dao.MyBatisUserDao;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.mapper.MapperFactoryBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.PlatformTransactionManager;

import javax.annotation.PostConstruct;

@SpringBootApplication

// 定义 MyBatis 的扫描
@MapperScan(
        // 指定扫描包
        basePackages = "com.wangju.chapter5.*",
        // 指定 SqlSessionFactory，如果 sqlSessionTemplate 被指定，则作废
        sqlSessionFactoryRef = "sqlSessionFactory",
        // 指定 sqlSessionTemplate，将忽略 sqlSessionFactory 的配置
        sqlSessionTemplateRef = "sqlSessionTemplate",
        // markerInterface = Class.class,// 限定扫描接口，不常用
        annotationClass = Repository.class
)
@EntityScan(basePackages = "com.wangju.chapter5.pojo")
public class Chapter5Application {

    ///home/wangju/Code/Java/chapter5/src/main/java/com/wangju/chapter5/mapper

//    @Autowired
//    SqlSessionFactory sqlSessionFactory;
//
//    @Bean
//    public FactoryBean<MyBatisUserDao> initMyBatisUserDao() {
//
//        MapperFactoryBean<MyBatisUserDao> bean = new MapperFactoryBean<>();
//        bean.setMapperInterface(MyBatisUserDao.class);
//        bean.setSqlSessionFactory(this.sqlSessionFactory);
//        return bean;
//    }

    @Autowired
    PlatformTransactionManager transactionManager;


    // 使用后初始化方法，观察自动生成的事务管理器
    @PostConstruct
    public void viewTransactionManager() {
        // 启动前加入断点观测
        System.out.println(transactionManager.getClass().getName());
    }

    public static void main(String[] args) {
        SpringApplication.run(Chapter5Application.class, args);
    }

}

